import java.util.*;

public class Shape {
	int[][] rot1;
	int[][] rot2;
	int[][] rot3;
	int[][] rot4;
	int color;
	int shapeNum;
	int NumOfRots;
	int column = 4;
	int row = 0;
	int[][] locs;

	public Shape() {
		Random rand = new Random();
		column = 5;
		row = 3;
		shapeNum = rand.nextInt(7);
		switch (shapeNum) {
		case 0:
			rot1 = new int[][] { { 1, 1, 1, 1 }, { 0, 0, 0, 0 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			rot2 = new int[][] { { 0, 1, 0, 0 }, { 0, 1, 0, 0 },
					{ 0, 1, 0, 0 }, { 0, 1, 0, 0 } };
			NumOfRots = 2;
			break;
		case 1:
			rot1 = new int[][] { { 0, 2, 2, 0 }, { 0, 2, 2, 0 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			NumOfRots = 1;
			break;
		case 2:
			rot1 = new int[][] { { 0, 3, 0, 0 }, { 0, 3, 3, 0 },
					{ 0, 0, 3, 0 }, { 0, 0, 0, 0 } };
			rot2 = new int[][] { { 0, 3, 3, 0 }, { 3, 3, 0, 0 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			NumOfRots = 2;
			break;
		case 3:
			rot1 = new int[][] { { 0, 0, 4, 0 }, { 0, 4, 4, 0 },
					{ 0, 4, 0, 0 }, { 0, 0, 0, 0 } };
			rot2 = new int[][] { { 0, 4, 4, 0 }, { 0, 0, 4, 4 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			NumOfRots = 2;
			break;
		case 4:
			rot1 = new int[][] { { 0, 5, 0, 0 }, { 0, 5, 0, 0 },
					{ 0, 5, 5, 0 }, { 0, 0, 0, 0 } };
			rot2 = new int[][] { { 0, 5, 5, 5 }, { 0, 5, 0, 0 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			rot3 = new int[][] { { 0, 5, 5, 0 }, { 0, 0, 5, 0 },
					{ 0, 0, 5, 0 }, { 0, 0, 0, 0 } };
			rot4 = new int[][] { { 0, 0, 5, 0 }, { 5, 5, 5, 0 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			NumOfRots = 4;
			break;
		case 5:
			rot1 = new int[][] { { 0, 0, 6, 0 }, { 0, 0, 6, 0 },
					{ 0, 6, 6, 0 }, { 0, 0, 0, 0 } };
			rot2 = new int[][] { { 0, 6, 0, 0 }, { 0, 6, 6, 6 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			rot3 = new int[][] { { 0, 6, 6, 0 }, { 0, 6, 0, 0 },
					{ 0, 6, 0, 0 }, { 0, 0, 0, 0 } };
			rot4 = new int[][] { { 6, 6, 6, 0 }, { 0, 0, 6, 0 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			NumOfRots = 4;
			break;
		case 6:
			rot1 = new int[][] { { 0, 7, 0, 0 }, { 0, 7, 7, 0 },
					{ 0, 7, 0, 0 }, { 0, 0, 0, 0 } };
			rot2 = new int[][] { { 0, 7, 7, 7 }, { 0, 0, 7, 0 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			rot3 = new int[][] { { 0, 0, 7, 0 }, { 0, 7, 7, 0 },
					{ 0, 0, 7, 0 }, { 0, 0, 0, 0 } };
			rot4 = new int[][] { { 0, 0, 7, 0 }, { 0, 7, 7, 7 },
					{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
			NumOfRots = 4;
			break;
		}
		locs = rot1;
		
	}

	public void turnc() {

		if (locs == rot1 && NumOfRots >= 2
				&& Board.checkSpace(row, column, rot2, "c")) {
			locs = rot2;
		} else if (locs == rot2) {
			if (NumOfRots == 2 && Board.checkSpace(row, column, rot1, "c")) {
				locs = rot1;
			} else if (NumOfRots == 4
					&& Board.checkSpace(row, column, rot3, "c")) {
				locs = rot3;
			}
		} else if (locs == rot3 && Board.checkSpace(row, column, rot4, "c")) {
			locs = rot4;
		} else if (locs == rot4 && Board.checkSpace(row, column, rot1, "c")) {
			locs = rot1;
		}
		
	}

	public void turncc() {
		if (locs == rot1) {
			if (NumOfRots == 2 && Board.checkSpace(row, column, rot2, "cc")) {
				locs = rot2;
			} else if (NumOfRots == 4
					&& Board.checkSpace(row, column, rot4, "cc")) {
				locs = rot4;
			}
		} else if (locs == rot2 && Board.checkSpace(row, column, rot1, "cc")) {
			locs = rot1;
		} else if (locs == rot3 && Board.checkSpace(row, column, rot2, "cc")) {
			locs = rot2;
		} else if (locs == rot4 && Board.checkSpace(row, column, rot3, "cc")) {
			locs = rot3;
		}
	}

	public void moveleft() {
		if (Board.checkSpace(row, column, locs, "left")) {
			column--;
		}
	}

	public void moveRight() {
		if (Board.checkSpace(row, column, locs, "right")) {
			column++;
		}
	}

	public void moveDown() {
		if (Board.checkSpace(row, column, locs, "down")) {
			row++;
		}
	}
}
